package com.yu.rabbitmq.five;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.yu.rabbitmq.utils.RabbitMqUnits;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消息接收
 */
public class ReceiveLogs02 {

    //交换机名称
    public static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws IOException, TimeoutException {

            Channel channel = RabbitMqUnits.getChannel();
            channel.exchangeDeclare(EXCHANGE_NAME,"fanout");//声明交换机
            //生成一个临时队列
            String queue = channel.queueDeclare().getQueue();
            //绑定交换机和队列
            channel.queueBind(queue,EXCHANGE_NAME,"");
            System.out.println("等待接收消息。。。");

            DeliverCallback deliverCallback = ( consumerTag,message)->{
                System.out.println("ReceiveLogs02接收的消息是:"+new String(message.getBody(), "UTF-8"));
            };

            channel.basicConsume(queue,true,deliverCallback,consumerTag -> {});

    }
}
